package com.itheima.health.controller;

import com.itheima.health.DTO.OrderDTO;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Order;
import com.itheima.health.service.OrderService;
import com.itheima.health.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/mobile/order")
@Slf4j
public class OrderController {
    @Resource
    private OrderService orderService;

    @PostMapping("/submit")
    public Result submit(@RequestBody OrderDTO orderDTO) {
        Order order = orderService.submit(orderDTO);
        return new Result(true, MessageConst.ORDER_SUCCESS, order);
    }

    @GetMapping("/findById")
    public Result findById(Integer id) {
        OrderVO orderVO = orderService.findById(id);
        return new Result(true, MessageConst.QUERY_ORDER_SUCCESS, orderVO);
    }
}
